<?php
namespace app\index\controller;
use app\index\controller\Base;
use think\Session;
class Personal extends Base{
    public function index(){
        // return $this->fetch('personal');
    	if(!Session::get('username')){
    		$this->success('请先登陆！','Reg/index');
    	}else{
    		$username=Session::get('username');
    		$info=db('user')->where('username',$username)->select();
	    	$this->assign('info',$info);
    		return $this->fetch('personal');
        }
    }
    public function edit(){
    	$id=input('id');
        $users=db('user')->find($id);
    	if(request()->isPost()){
    		$data=[
                'auto'=>input('auto'), 
    			'email'=>input('email'),
                'user_city'=>input('user_city'),
                'user_sex'=>input('user_sex'),
                'birthday'=>input('birthday'),
                'qq'=>input('qq'),
            ];   
            if($_FILES['upic']['tmp_name']){
                $file = request()->file('upic');
                $info = $file->move(ROOT_PATH . 'public' . DS . 'static/uploads');
                $data['upic']='/uploads/'.$info->getSaveName();
            }      
            $save=db('user')->where('id',$id)->update($data);
    		if($save !== false){
    			$this->success('修改资料成功！','personal/index');
    		}else{
    			$this->error('修改资料失败！');
    		}
    		return;
    	}
    	$this->assign('users',$users);
    	return $this->fetch();
    }	
}
